<?php

	/**
	 * @see Bike_Plugin_Abstract
	 */
	require_once 'Bike/Plugin/Abstract.php';
	
	
	class Bike_Plugin_Config extends Bike_Plugin_Abstract
    {
        const CONFIG_PLUGIN_NAME = 'config';

        public function runForCli(Zend_Application $Application)
        {        	$this->setApplication($Application);
        	$this->routeStartup();
        }

        public function routeStartup()
        {        	$this->setOption(array(), $this->getOptions());
        }

        protected function setOption($NameArr, $Value)
        {        	try
        	{
		       	if(is_array($Value))
		       	{		       		foreach($Value as $name => $value)
		       		{
		       			$this->setOption(array_merge($NameArr, array($name)), $value);
		       		}
		       	}
		       	else
		       	{		       		require_once 'Bike/Plugin/Exception.php';
		       		throw new Bike_Plugin_Exception('Value is not array');
		       	}
		  	}
		  	catch(Bike_Plugin_Exception $e)
		  	{		  		array_unshift($NameArr, 'Bike');
        		$option = array_pop($NameArr);
        		$className = join('_', $NameArr);
        		$methodName = 'set'.ucfirst($option);
				if(!@class_exists($className))
        		{        			require_once 'Bike/Plugin/Exception.php';
        			throw new Bike_Plugin_Exception('Class '.$className.' is not exists');
        		}

        		if(is_callable(array($className, 'getInstance')))
        		{
        			return call_user_func(array($className, 'getInstance'))->$methodName($Value);
        		}
        		else
        		{
        			return call_user_func(array($className, $methodName), $Value);
        		}
		  	}
        }
    }
